using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class LoadDataPanel : BasePanel
{
    [SerializeField] private PlayerData playerData;
    [SerializeField] private Button startGame;
    [SerializeField] private Button returnButton;
    [SerializeField] private TMP_InputField inputUsername;
    
    
    //
    private void Start()
    {
        startGame.onClick.AddListener(StartGame);
        returnButton.onClick.AddListener(ReturnAction);
    }
    
    //
    private void StartGame()
    {
        PlayerData playerData = SaveDataSystem.LoadFromJson<PlayerData>(inputUsername.text);
        if (playerData == null)
        {
            print("存档"+inputUsername.text+"是空的");
            return;
        }
        this.playerData.playerBlood = playerData.playerBlood;
        this.playerData.playerScore = playerData.playerScore;
        this.playerData.playerPosition = playerData.playerPosition;
        this.playerData.sceneIndex = playerData.sceneIndex;
        
        // 加载存档场景
        EventCenter.Instance.EventTrigger(EventName.EVENT_SCENE_SCENESWITE, this.playerData.sceneIndex);
        
    }

    private void ReturnAction()
    {
        UIManager.Instance.ClosePanel(UIConst.PANEL_LOAD);
    }
}

// [SerializeField] private Button returnButton;
//     
//     
// // 
// void Start()
// {
//     returnButton.onClick.AddListener(ReturnButton);
// }
//
// //
// private void ReturnButton()
// {
//     //
//     UIManager.Instance.ClosePanel(UIConst.PANEL_LOAD);
// }
